import Vue from "vue";
import Vuex from "vuex";
import user from "./user";

Vue.use(Vuex);

export default new Vuex.Store({
    state: {
        random: 0,
        count: 0,
    },
    getters: {
        // 1. 相当于vue中计算属性
        dbCount(state) {
            console.log("dbCount触发了");
            return state.count * 2;
        },
        // 2. 快捷方式
        token: (state) => state.user.obj.token,
    },
    mutations: {
        setRandom(state) {
            // setTimeout(() => {
            state.random = Math.random();
            // }, 3000);
        },
        addCount(state) {
            state.count += 1;
        },
    },
    actions: {},
    modules: {
        user,
    },
});
